package com.gg.user.gguser.dao;


import com.gg.user.gguser.dataobject.GgContractDataobject;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GgContractDaoMapper {

    // 一共多少个
    //@Select("select count(*) from gg_contract")
    @Select({
            "<script>",
                "select count(*) from gg_contract where gg_c_user_id=#{ggIdUser}",
                "<if test='name!=null and name!=\"\"'>",
                    "and gg_c_contract_name like '%${name}%'",
                "</if>",
                "<if test='type!=null and name!=\"\"'>",
                    "and gg_c_type_of_contract = #{type}",
                "</if>",
                "<if test='starttime!=null and name!=\"\"'>",
                    "and gg_c_update >= #{starttime}",
                "</if>",
                "<if test='endtime!=null and name!=\"\"'>",
                    "and  #{endtime} >= gg_c_update",
                "</if>"
            ,"</script>"
    })
    Integer getContractSelectCount(@Param("ggIdUser")String ggIdUser,@Param("name")String name,@Param("type") String type,@Param("starttime")String starttime,@Param("endtime")String endtime);

    // 列表
    //@Select("select gg_c_id as ggCId, gg_c_number as ggCNumber, gg_c_contract_name as ggCContractName, gg_c_institutional_name as ggCInstitutionalName, gg_c_type_of_contract as ggCTypeOfContract, gg_c_contract_amount as ggCcontractAmount, gg_c_person_in_charge as ggCpersonInCharge, gg_c_contract_time as ggCContractTime, gg_c_due_time as ggCDueTime, gg_c_nature_of_contract as ggCNatureOfContract, gg_c_contract_contact as ggCContractContact, gg_c_total_contract_amount as ggCTotalContractAmount, gg_c_payment_method as ggCPaymentMethod, gg_c_signed_by as ggCSignedBy, gg_c_signature_of_contract as ggCSignatureOfContract, gg_c_remarks as ggCRemarks, gg_c_ppload_information as ggCPploadInformation, gg_c_expiration_reminder as ggCExpirationReminder, gg_c_user_id as ggCUserId, gg_c_time as ggCTime, gg_c_update as ggCUpdate from gg_contract  order by gg_c_update desc limit #{page},#{pageNumber}")
    @Select({
            "<script>",
            "select gg_c_id as ggCId, gg_c_number as ggCNumber, gg_c_contract_name as ggCContractName, gg_c_institutional_name as ggCInstitutionalName, gg_c_type_of_contract as ggCTypeOfContract, gg_c_contract_amount as ggCcontractAmount, gg_c_person_in_charge as ggCpersonInCharge, gg_c_contract_time as ggCContractTime, gg_c_due_time as ggCDueTime, gg_c_nature_of_contract as ggCNatureOfContract, gg_c_contract_contact as ggCContractContact, gg_c_total_contract_amount as ggCTotalContractAmount, gg_c_payment_method as ggCPaymentMethod, gg_c_signed_by as ggCSignedBy, gg_c_signature_of_contract as ggCSignatureOfContract, gg_c_remarks as ggCRemarks, gg_c_ppload_information as ggCPploadInformation, gg_c_expiration_reminder as ggCExpirationReminder, gg_c_user_id as ggCUserId, gg_c_time as ggCTime, gg_c_update as ggCUpdate from gg_contract where gg_c_user_id=#{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_c_contract_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_c_type_of_contract = #{type}",
            "</if>",
            "<if test='starttime!=null and name!=\"\"'>",
            "and gg_c_update >= #{starttime}",
            "</if>",
            "<if test='endtime!=null and name!=\"\"'>",
            "and  #{endtime} >= gg_c_update",
            "</if>",
            "order by gg_c_update desc limit #{page},#{pageNumber}"
            ,"</script>"
    })
    List<GgContractDataobject> getContractSelectList(@Param("ggIdUser")String ggIdUser,@Param("page")Integer page, @Param("pageNumber")Integer pageNumber, @Param("name")String name,@Param("type") String type,@Param("starttime")String starttime,@Param("endtime")String endtime);


    /**
     * 单个查询
     */
    @Select("select gg_c_id as ggCId, gg_c_number as ggCNumber, gg_c_contract_name as ggCContractName, gg_c_institutional_name as ggCInstitutionalName, gg_c_type_of_contract as ggCTypeOfContract, gg_c_contract_amount as ggCcontractAmount, gg_c_person_in_charge as ggCpersonInCharge, gg_c_contract_time as ggCContractTime, gg_c_due_time as ggCDueTime, gg_c_nature_of_contract as ggCNatureOfContract, gg_c_contract_contact as ggCContractContact, gg_c_total_contract_amount as ggCTotalContractAmount, gg_c_payment_method as ggCPaymentMethod, gg_c_signed_by as ggCSignedBy, gg_c_signature_of_contract as ggCSignatureOfContract, gg_c_remarks as ggCRemarks, gg_c_ppload_information as ggCPploadInformation, gg_c_expiration_reminder as ggCExpirationReminder, gg_c_user_id as ggCUserId, gg_c_time as ggCTime, gg_c_update as ggCUpdate, gg_c_contract_seal as ggCContractSeal, gg_c_audit_status as ggCAuditStatus from gg_contract where gg_c_id = #{id} and gg_c_user_id = #{ggIdUser}")
    GgContractDataobject getContractItems(@Param("ggIdUser")String ggIdUser,@Param("id")Integer id);

    /**
     * 修改信息
     */
    @Update("update gg_contract set  gg_c_number = #{ggCNumber}, gg_c_contract_name = #{ggCContractName}, gg_c_institutional_name = #{ggCInstitutionalName}, gg_c_type_of_contract = #{ggCTypeOfContract}, gg_c_contract_amount = #{ggCcontractAmount}, gg_c_person_in_charge = #{ggCpersonInCharge}, gg_c_contract_time = #{ggCContractTime}, gg_c_due_time = #{ggCDueTime}, gg_c_nature_of_contract = #{ggCNatureOfContract}, gg_c_contract_contact = #{ggCContractContact}, gg_c_total_contract_amount = #{ggCTotalContractAmount}, gg_c_payment_method = #{ggCPaymentMethod}, gg_c_signed_by = #{ggCSignedBy}, gg_c_signature_of_contract = #{ggCSignatureOfContract}, gg_c_remarks = #{ggCRemarks}, gg_c_ppload_information = #{ggCPploadInformation}, gg_c_expiration_reminder = #{ggCExpirationReminder},   gg_c_contract_seal = #{ggCContractSeal}, gg_c_audit_status = #{ggCAuditStatus} where gg_c_user_id = #{ggCUserId} and gg_c_id = #{ggCId}")
    Integer updateContractItems(@Param("ggCNumber")String ggCNumber, @Param("ggCContractName")String ggCContractName, @Param("ggCInstitutionalName")String ggCInstitutionalName, @Param("ggCTypeOfContract")String ggCTypeOfContract, @Param("ggCcontractAmount")String ggCcontractAmount, @Param("ggCpersonInCharge")String ggCpersonInCharge, @Param("ggCContractTime")String ggCContractTime, @Param("ggCDueTime")String ggCDueTime, @Param("ggCNatureOfContract")String ggCNatureOfContract, @Param("ggCContractContact")String ggCContractContact, @Param("ggCTotalContractAmount")String ggCTotalContractAmount, @Param("ggCPaymentMethod")String ggCPaymentMethod, @Param("ggCSignedBy")String ggCSignedBy, @Param("ggCSignatureOfContract")String ggCSignatureOfContract, @Param("ggCRemarks")String ggCRemarks, @Param("ggCPploadInformation")String ggCPploadInformation, @Param("ggCExpirationReminder")String ggCExpirationReminder, @Param("ggCContractSeal")String ggCContractSeal, @Param("ggCAuditStatus")String ggCAuditStatus, @Param("ggCUserId")String ggCUserId, @Param("ggCId")Integer ggCId);

    /**
     * 增加合同
     */
    @Insert("insert into gg_contract(gg_c_number , gg_c_contract_name , gg_c_institutional_name , gg_c_type_of_contract , gg_c_contract_amount , gg_c_person_in_charge , gg_c_contract_time , gg_c_due_time , gg_c_nature_of_contract , gg_c_contract_contact , gg_c_total_contract_amount , gg_c_payment_method , gg_c_signed_by , gg_c_signature_of_contract , gg_c_remarks, gg_c_ppload_information , gg_c_expiration_reminder ,   gg_c_contract_seal , gg_c_audit_status , gg_c_user_id) values (#{ggCNumber}, #{ggCContractName}, #{ggCInstitutionalName}, #{ggCTypeOfContract}, #{ggCcontractAmount}, #{ggCpersonInCharge}, #{ggCContractTime}, #{ggCDueTime}, #{ggCNatureOfContract}, #{ggCContractContact}, #{ggCTotalContractAmount}, #{ggCPaymentMethod}, #{ggCSignedBy}, #{ggCSignatureOfContract}, #{ggCRemarks}, #{ggCPploadInformation}, #{ggCExpirationReminder},  #{ggCContractSeal}, #{ggCAuditStatus} ,#{ggCUserId})")
    Integer addContractItems(@Param("ggCNumber")String ggCNumber, @Param("ggCContractName")String ggCContractName, @Param("ggCInstitutionalName")String ggCInstitutionalName, @Param("ggCTypeOfContract")String ggCTypeOfContract, @Param("ggCcontractAmount")String ggCcontractAmount, @Param("ggCpersonInCharge")String ggCpersonInCharge, @Param("ggCContractTime")String ggCContractTime, @Param("ggCDueTime")String ggCDueTime, @Param("ggCNatureOfContract")String ggCNatureOfContract, @Param("ggCContractContact")String ggCContractContact, @Param("ggCTotalContractAmount")String ggCTotalContractAmount, @Param("ggCPaymentMethod")String ggCPaymentMethod, @Param("ggCSignedBy")String ggCSignedBy, @Param("ggCSignatureOfContract")String ggCSignatureOfContract, @Param("ggCRemarks")String ggCRemarks, @Param("ggCPploadInformation")String ggCPploadInformation, @Param("ggCExpirationReminder")String ggCExpirationReminder, @Param("ggCContractSeal")String ggCContractSeal, @Param("ggCAuditStatus")String ggCAuditStatus, @Param("ggCUserId")String ggCUserId);

    /**
     * 删除合同
     */
    @Delete("delete from gg_contract where gg_c_id=#{ggCId} and gg_c_user_id = #{ggCUserId}")
    Integer delectContract(@Param("ggCId")Integer ggCId, @Param("ggCUserId")String ggCUserId);
}
